package com.baiytfp.hf.HFDataExchange.action.controller.view;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.baiytfp.hf.HFDataExchange.common.base.anotation.Auth;
import com.baiytfp.hf.HFDataExchange.common.utils.PathInfo;
import com.baiytfp.hf.baiytfp.framework.model.table.Config;
import com.baiytfp.hf.baiytfp.framework.util.CommonUtil;
import com.baiytfp.hf.baiytfp.hfutils.HFConfig;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.baiytfp.hf.baiytfp.framework.base.BaseController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Controller
@RequestMapping("/view/admin")
public class AdminVController extends BaseController {


	public AdminVController() {

	}

	/**
	 * 修改面貌
	 */
	@RequestMapping("/modifypassword")
	public ModelAndView modifypassword(HttpServletRequest request,HttpServletResponse response) throws Exception {
		ModelAndView mav = new ModelAndView();


		return mav;
	}
	
	/**
	 * 进入用户管理首页
	 */
	@RequestMapping("/index")
	public ModelAndView index(HttpServletRequest request,HttpServletResponse response) throws Exception {
		ModelAndView mav = new ModelAndView();

		mav.addObject("home_logo", HFConfig.getIstance().getDBConfig("HOME_LOGO", PathInfo.getSkinPath(request) + "hongfeng/index-logo.png"));
		String homePage = HFConfig.getIstance().getPropConfig("home_page");
		mav.addObject("home_page", CommonUtil.isEmpty(homePage)
				? request.getServletContext().getContextPath() + "/view/index/welcome.do"
				: homePage);
		return mav;
	}

	@RequestMapping("/setconfig")
	@Auth(checkMenu=true)
	public ModelAndView setconfig(HttpServletRequest request,
								  HttpServletResponse response) throws Exception {
		ModelAndView mav = new ModelAndView();

		List<Config> list0 = HFConfig.getIstance().getConfigList("", "0");
		List<Config> list10 = HFConfig.getIstance().getConfigList("1", "0");
		if (list10 == null) {
			list10 = new ArrayList();
		}
		List<Config> list20 = HFConfig.getIstance().getConfigList("2", "0");
		if (list20 == null) {
			list20 = new ArrayList();
		}

		//转化为KeyValue
		Map<String, String> map = new HashMap();
		for(Config configVO : list0){
			map.put(configVO.getThe_key(), configVO.getThe_value());
		}

		mav.addObject("config", map);
		mav.addObject("dynamic_config", list10);
		mav.addObject("menu_config", list20);
		mav.addObject("d_num", list10.size() + "");
		mav.addObject("m_num", list20.size() + "");
		mav.addObject("c_num", (list10.size() + list20.size()) + "");
		return mav;
	}
	
	
	@RequestMapping("/count")
	public ModelAndView count(HttpServletRequest request) {
		ModelAndView mav = new ModelAndView("admin/count");
		mav.addObject("type", request.getParameter("type"));
		return mav;
	}

}
